package com.lingchen.controller;

import com.lingchen.entity.Choice;
import com.lingchen.response.Result;
import com.lingchen.response.ResultUtil;
import com.lingchen.service.ChoiceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Author    lingchen
 * Email     838878458@qq.com
 * Time      2018/2/27
 * Function  题目
 */
@Controller
@RequestMapping("/choice")
public class ChoiceController {
    @Autowired
    private ChoiceService choiceService;

    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public Result<String> selectAllInfo( Choice choice) {
        if (choiceService.insertChoice(choice) != 0) {
            return ResultUtil.success();
        } else {
            return ResultUtil.error("添加失败");
        }
    }

    @RequestMapping(value = "/index", method = RequestMethod.GET)
    public String index(String courseId,String userName, Model model) {
        model.addAttribute("courseId", courseId);
        model.addAttribute("userName", userName);
        return "addChoice";
    }


}
